package com.xveshe.admin.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import com.xveshe.admin.domain.XsglXsxx;
import com.xveshe.admin.mapper.XsglXsxxMapper;
import com.xveshe.common.utils.DateUtils;
import com.xveshe.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xveshe.admin.mapper.XsglXslbMapper;
import com.xveshe.admin.domain.XsglXslb;
import com.xveshe.admin.service.IXsglXslbService;

/**
 * 学社类别Service业务层处理
 *
 * @author 葛亚松
 * @date 2024-11-01
 */
@Service
public class XsglXslbServiceImpl implements IXsglXslbService
{
    @Autowired
    private XsglXslbMapper xsglXslbMapper;
    @Autowired
    private XsglXsxxMapper xsglXsxxMapper;

    /**
     * 查询学社类别
     *
     * @param id 学社类别主键
     * @return 学社类别
     */
    @Override
    public XsglXslb selectXsglXslbById(String id)
    {
        return xsglXslbMapper.selectXsglXslbById(id);
    }

    /**
     * 查询学社类别列表
     *
     * @param xsglXslb 学社类别
     * @return 学社类别
     */
    @Override
    public List<XsglXslb> selectXsglXslbList(XsglXslb xsglXslb)
    {
        return xsglXslbMapper.selectXsglXslbList(xsglXslb);
    }

    /**
     * 新增学社类别
     *
     * @param xsglXslb 学社类别
     * @return 结果
     */
    @Override
    public int insertXsglXslb(XsglXslb xsglXslb)
    {
        xsglXslb.setId(UUID.randomUUID().toString());
        //获取用户账号xsglXslb.setCreator(SecurityUtils.getUsername());
        //获取用户昵称
        xsglXslb.setCreator(SecurityUtils.getLoginUser().getUser().getNickName());
        xsglXslb.setCreatedate(DateUtils.getNowDate());
        return xsglXslbMapper.insertXsglXslb(xsglXslb);
    }

    /**
     * 修改学社类别
     *
     * @param xsglXslb 学社类别
     * @return 结果
     */
    @Override
    public int updateXsglXslb(XsglXslb xsglXslb)
    {
        xsglXslb.setLastmodifier(SecurityUtils.getLoginUser().getUser().getNickName());
        xsglXslb.setLastmodifieddate(DateUtils.getNowDate());
        return xsglXslbMapper.updateXsglXslb(xsglXslb);
    }

    /**
     * 批量删除学社类别
     *
     * @param ids 需要删除的学社类别主键
     * @return 结果
     */
    @Override
    public int deleteXsglXslbByIds(String[] ids)
    {
        int result = 0;
        XsglXsxx xsxx = new XsglXsxx();
        for (String id : ids){
            xsxx.setXsxxXslb(id);
            if(xsglXsxxMapper.selectXsglXsxxList(xsxx).size()==0) {
                result+=xsglXslbMapper.deleteXsglXslbById(id);
            }
        }
        return result;
    }

    /**
     * 删除学社类别信息
     *
     * @param id 学社类别主键
     * @return 结果
     */
    @Override
    public int deleteXsglXslbById(String id)
    {
        return xsglXslbMapper.deleteXsglXslbById(id);
    }
}
